package com.binarysoft.service.user;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.binarysoft.service.user.UserInfo;

public class UserInfoSqlProvider {

    public String insertSelective(UserInfo record) {
        BEGIN();
        INSERT_INTO("user_info");
        
        VALUES("id", "#{id,jdbcType=INTEGER}");
        
        if (record.getName() != null) {
            VALUES("name", "#{name,jdbcType=VARCHAR}");
        }
        
        if (record.getSurname() != null) {
            VALUES("surname", "#{surname,jdbcType=VARCHAR}");
        }
        
        if (record.getDescription() != null) {
            VALUES("description", "#{description,jdbcType=VARCHAR}");
        }
        
        if (record.getEmail() != null) {
            VALUES("email", "#{email,jdbcType=VARCHAR}");
        }
        
        if (record.getPhoneNum() != null) {
            VALUES("phone_num", "#{phoneNum,jdbcType=VARCHAR}");
        }
        
        if (record.getLocale() != null) {
            VALUES("locale", "#{locale,jdbcType=VARCHAR}");
        }
        
        if (record.getActive() != null) {
            VALUES("active", "#{active,jdbcType=INTEGER}");
        }
        
        if (record.getDeleted() != null) {
            VALUES("deleted", "#{deleted,jdbcType=INTEGER}");
        }
        
        if (record.getLoginId() != null) {
            VALUES("login_id", "#{loginId,jdbcType=VARCHAR}");
        }
        
        if (record.getLoginPass() != null) {
            VALUES("login_pass", "#{loginPass,jdbcType=VARCHAR}");
        }
        
        if (record.getCreationTime() != null) {
            VALUES("creation_time", "#{creationTime,jdbcType=DATE}");
        }
        
        if (record.getLastUpdatedTime() != null) {
            VALUES("last_updated_time", "#{lastUpdatedTime,jdbcType=DATE}");
        }
        
        if (record.getLastLoginTime() != null) {
            VALUES("last_login_time", "#{lastLoginTime,jdbcType=DATE}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(UserInfo record) {
        BEGIN();
        UPDATE("user_info");
        
        if (record.getName() != null) {
            SET("name = #{name,jdbcType=VARCHAR}");
        }
        
        if (record.getSurname() != null) {
            SET("surname = #{surname,jdbcType=VARCHAR}");
        }
        
        if (record.getDescription() != null) {
            SET("description = #{description,jdbcType=VARCHAR}");
        }
        
        if (record.getEmail() != null) {
            SET("email = #{email,jdbcType=VARCHAR}");
        }
        
        if (record.getPhoneNum() != null) {
            SET("phone_num = #{phoneNum,jdbcType=VARCHAR}");
        }
        
        if (record.getLocale() != null) {
            SET("locale = #{locale,jdbcType=VARCHAR}");
        }
        
        if (record.getActive() != null) {
            SET("active = #{active,jdbcType=INTEGER}");
        }
        
        if (record.getDeleted() != null) {
            SET("deleted = #{deleted,jdbcType=INTEGER}");
        }
        
        if (record.getLoginId() != null) {
            SET("login_id = #{loginId,jdbcType=VARCHAR}");
        }
        
        if (record.getLoginPass() != null) {
            SET("login_pass = #{loginPass,jdbcType=VARCHAR}");
        }
        
        if (record.getCreationTime() != null) {
            SET("creation_time = #{creationTime,jdbcType=DATE}");
        }
        
        if (record.getLastUpdatedTime() != null) {
            SET("last_updated_time = #{lastUpdatedTime,jdbcType=DATE}");
        }
        
        if (record.getLastLoginTime() != null) {
            SET("last_login_time = #{lastLoginTime,jdbcType=DATE}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}